package com._51cto.healthy.controller;


import com._51cto.healthy.content.R;
import com._51cto.healthy.pojo.OrderSetting;
import com._51cto.healthy.security.SecurityUser;
import com._51cto.healthy.service.OrderSettingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpSession;
import java.util.List;

@Api(value = "预约设置管理", tags = "预约设置管理")
@RestController
@CrossOrigin
@RequestMapping("/order-setting")
public class OrderSettingController {

    @DubboReference
    private OrderSettingService orderSettingService;

    @ApiOperation(value = "预约设置信息", notes = "获取当前用户的预约设置信息", tags = "预约设置管理")
    @GetMapping()
    public R queryOrderSetting(@CookieValue("adminToken")String token , @ApiIgnore HttpSession session){
        //获取token
        SecurityUser attribute = (SecurityUser) session.getAttribute(token);
        //根据用户id查询
        List<OrderSetting> orderSettings = orderSettingService.queryByUserId(attribute.getId());
        return R.success(orderSettings);
    }

    @ApiOperation(value = "预约设置删除", notes = "预约设置-主键删除", tags = "预约设置管理")
    @DeleteMapping("/{id}")
    public R delete(@PathVariable("id") Integer pk){
        orderSettingService.deleteByPK(pk);
        return R.success("删除成功");
    }

    @ApiOperation(value = "预约设置新增", notes = "新增预约设置信息", tags = "预约设置管理")
    @PostMapping()
    public R insert(@CookieValue("adminToken")String token,@RequestBody OrderSetting orderSetting, @ApiIgnore HttpSession session){
        SecurityUser attribute = (SecurityUser) session.getAttribute(token);
        orderSettingService.insert(orderSetting.setUserId(attribute.getId()));
        return R.success("添加成功");
    }

    @ApiOperation(value = "预约设置编辑", notes = "编辑预约设置信息", tags = "预约设置管理")
    @PutMapping()
    public R update(@RequestBody OrderSetting orderSetting){
        orderSettingService.update(orderSetting);
        return R.success("修改成功");
    }


}
